package com.wzdigit.wms.raw.controller.asn.report;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.raw.client.request.asn.report.ortherasn.OrtherAsnRequest;
import com.wzdigit.wms.raw.client.response.asn.report.ortherasn.OrtherAsnDtlGoodsResponse;
import com.wzdigit.wms.raw.client.response.asn.report.ortherasn.OrtherAsnDtlResponse;
import com.wzdigit.wms.raw.client.response.asn.report.ortherasn.OrtherAsnResponse;
import com.wzdigit.wms.raw.client.response.asn.report.ortherasn.OrtherAsnEnums;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.service.asn.report.OrtherAsnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 其他入库单Controller
 * Created by zyf on 2021/6/9 19:17
 */
@RestController
@Api(tags = "其他入库单")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class OrtherAsnController {
    private final String REQUEST_MODEL = "/OrtherAsn";

    @Autowired
    private OrtherAsnService ortherAsnService;

    @ApiOperation(value = "获取其他入库单主页（分页）", notes = "获取其他入库单主页（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/Header", method = RequestMethod.GET)
    public PagerInfo<List<OrtherAsnResponse>> searchOrtherAsnHeader(
            OrtherAsnRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return ortherAsnService.searchOrtherAsnHeader(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "获取其他入库单明细（分页）", notes = "获取其他入库单明细（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/Dtl", method = RequestMethod.GET)
    public PagerInfo<List<OrtherAsnDtlResponse>> searchOrtherAsnDtl(
            BigDecimal asnHeaderId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return ortherAsnService.searchOrtherAsnDtl(asnHeaderId,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "获取其他入库单序列（分页）", notes = "获取其他入库单序列（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/DtlGoods", method = RequestMethod.GET)
    public PagerInfo<List<OrtherAsnDtlGoodsResponse>> searchOrtherAsnDtlGoods(
            BigDecimal asnHeaderId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return ortherAsnService.searchOrtherAsnDtlGoods(asnHeaderId,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出其他入库单", notes = "导出其他入库单")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportSaleInv", method = RequestMethod.POST)
    public void exportOrtherAsnReport(
            @RequestBody OrtherAsnRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            ortherAsnService.exportOrtherAsnReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "单据类型下拉框", notes = "单据类型下拉框")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/getEnums", method = RequestMethod.GET)
    public List<OrtherAsnEnums> getEnums(
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return ortherAsnService.getOrtherAsnEnumsList();
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    @ApiOperation(value = "订单状态下拉框", notes = "订单状态下拉框")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/getStatusEnums", method = RequestMethod.GET)
    public List<Map<Integer,String>> getStatusEnum(
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return ortherAsnService.getAsnStatusEnum();
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }




}
